using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using enqueteJwVd;
using enqueteJwVd.Models;
using enqueteJwVd.DAL;
using enqueteJwVd.Services;
using enqueteJwVd.ViewModels;

namespace enqueteJwVd.Controllers
{
    [Authorize(Roles = "e-manager")]
    public class CheckBoxOptionsController : Controller
    {
        UnitOfWork unitOfWork = new UnitOfWork();
        ICheckBoxOptionService checkBoxOptionService; 

		public CheckBoxOptionsController(ICheckBoxOptionService checkBoxOptionService)
        {
            this.checkBoxOptionService = checkBoxOptionService;
        }

        public CheckBoxOptionsController()
        {
            
        }

        //
        // GET: /CheckBoxOptions/

        public ViewResult Index()
        {
            var checkBoxOptions = checkBoxOptionService.GetAllCheckBoxOptions();
            var viewModel = new CheckBoxOptionIndexViewModel() { CheckBoxOptions = checkBoxOptions };
            return View(viewModel);
        }

        //
        // GET: /CheckBoxOptions/Details/5

        public ViewResult Details(int id)
        {
            CheckBoxOptions checkBoxOptions = unitOfWork.CheckBoxOptionRepository.GetById(id);
            return View(checkBoxOptions);
        }

        //
        // GET: /CheckBoxOptions/Create

        public ActionResult Create()
        {
            return View();
        } 

        //
        // POST: /CheckBoxOptions/Create

        [HttpPost]
        public ActionResult Create(CheckBoxOptions checkboxoptions)
        {
            if (ModelState.IsValid) {
                unitOfWork.CheckBoxOptionRepository.Add(checkboxoptions);
                unitOfWork.SaveChanges();
                return RedirectToAction("Index"); 
            }

            return View(checkboxoptions);
        }
        
        //
        // GET: /CheckBoxOptions/Edit/5
 
        public ActionResult Edit(int id)
        {
            CheckBoxOptions checkBoxOptions = unitOfWork.CheckBoxOptionRepository.GetById(id);
             return View(checkBoxOptions);
        }

        //
        // POST: /CheckBoxOptions/Edit/5

        [HttpPost]
        public ActionResult Edit(CheckBoxOptions checkboxoptions)
        {
            if (ModelState.IsValid) {
                unitOfWork.CheckBoxOptionRepository.Update(checkboxoptions);
                unitOfWork.SaveChanges();
                return RedirectToAction("Index");
            }
            return View(checkboxoptions);
        }

        //
        // GET: /CheckBoxOptions/Delete/5
 
        public ActionResult Delete(int id)
        {
            CheckBoxOptions checkBoxOptions = unitOfWork.CheckBoxOptionRepository.GetById(id);
            return View(checkBoxOptions);
        }

        //
        // POST: /CheckBoxOptions/Delete/5

        [HttpPost, ActionName("Delete")]
        public ActionResult DeleteConfirmed(int id)
        {
            CheckBoxOptions checkBoxOptions = unitOfWork.CheckBoxOptionRepository.GetById(id);
            unitOfWork.CheckBoxOptionRepository.Delete(checkBoxOptions);
            unitOfWork.SaveChanges();

            return RedirectToAction("Index");
        }

        protected override void Dispose(bool disposing)
        {
            unitOfWork.Dispose();
            base.Dispose(disposing);
        }
    }
}

